<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 前台维权投诉ajax类
 * @package  ajax
 * @subpackage  shop
 * @author   create by allen.qiang
 */

quanli_require('module/base/bill/billComplain.class.php');

class ajax_billComplain {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && quanli_is_int($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //查看维权投诉
                    $this->searchComplain();
                    break;

                case 3: //提交维权投诉
                    $this->submitBillComplain();
                    break;

                default:
                    returnJsonData('参数错误');
                    break;


            }

        } else {
            returnJsonData('参数错误');
        }

    }

    private function searchComplain() {

        global $G_SHOP;

        //检查是否登录
        if (!$G_SHOP->currentPCustID) {
            returnJsonData('请先登录', 404);
        }

        if (!isset($_REQUEST['bill_no'])) {
            returnJsonData('参数错误');
        }


        //实例维权投诉类
        $billComplain = new billComplain();

        $args_array = array(
            'bill_no'=>$_REQUEST['bill_no']
        );

        $billComplain_array = $billComplain->billComplainSearch( $args_array );


        if ( !$billComplain_array ) {

            returnJsonData('暂无维权投诉信息', 404);
        } else {
            returnJsonData('ok',200,$billComplain_array);
        }

    }



    /**
     * 提交维权投诉
     */
    private function submitBillComplain() {

        global $G_SHOP;


        //检查是否登录
        if (!$G_SHOP->currentPCustID) {
            returnJsonData('请先登录', 404);
        }

        //实例商品评论类
        $billComplain = new billComplain();

        //保存商品评论
        $_REQUEST['operator'] = $G_SHOP->currentCustomerID;
        $_REQUEST['pcustID'] = $G_SHOP->currentPCustID;

        //引用会员类
        quanli_require('module/base/customer/customerManage.class.php');
        $customerManage = new customerManage( $G_SHOP->DBCA);
        $arg_array = array(
            'pcustID' => $_REQUEST['pcustID']
        );

        $customerManage_array = $customerManage->getCustomerInfo( $arg_array );
        if( !$customerManage_array ){
            returnJsonData('暂无该会员信息',404);
        }

        $_REQUEST['mobile'] = $customerManage_array[0]['mobile'];
        $_REQUEST['phone'] = $customerManage_array[0]['phone'];
        $_REQUEST['cust_name'] = $customerManage_array[0]['custID'];

        $result_array = $billComplain->saveBillComplain( $_REQUEST );

        returnJsonData($result_array['message'], $result_array['code']);


    }



}